package com.cj.framework.app;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;

/**
 * Created by cj on 2016/5/6.
 * Email:781806481@qq.com
 */
public abstract class BaseActivity extends AppCompatActivity{

    protected abstract void findId();
    protected abstract void logic();
    protected  abstract int setLayout();

    protected boolean isTranslucent(){
        return true;
    }

    private void setTranslucent(){
        Window window=getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    }

    private boolean checkTranslucent(){
        if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.KITKAT){
            return true;
        }else{
            return false;
        }
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(setLayout());
        if(isTranslucent()&&checkTranslucent()){
            setTranslucent();
        }
        findId();
        logic();
    }

    protected  void openActivity(Class<?> pClass,Bundle bundle){
        Intent intent=new Intent(this,pClass);
        if(bundle!=null){
            intent.putExtras(bundle);
        }
        startActivity(intent);
    }

    protected  void openActivity(Class<?> pClass){
        openActivity(pClass,null);
    }
}
